package com.e.library.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.e.library.R;
import com.github.ybq.android.spinkit.SpinKitView;
import com.github.ybq.android.spinkit.sprite.Sprite;

/**
 * Created by lxy on 2016/7/15.
 */
public class ELoading extends Dialog {

    private TextView tvLoading;
    private SpinKitView skvLoading;

    public ELoading(Context context) {
        super(context, com.e.library.R.style.loading_dialog);
        initView(context);
    }

    private void initView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null);
        tvLoading = (TextView) view.findViewById(R.id.tv_loading);
        skvLoading = (SpinKitView) view.findViewById(R.id.skv_loading);
        setContentView(view);
        setCancelable(false);
        setCanceledOnTouchOutside(false);
    }

    public void setSprite(Sprite sprite) {
        skvLoading.setIndeterminateDrawable(sprite);
    }

    public void showLoading(int text) {
        try {
            tvLoading.setText(text);
            show();
        }catch (Exception e){
            return;
        }

    }

    public void showLoading(String text) {
        try {
            tvLoading.setText(text);
            show();
        }catch (Exception e){
            return;
        }

    }
}
